import { asyncRouters, constantRoutes } from '@/router/index.js'

// 设置state变量
const state = {
  routePermissions: []
}

// 设置mutantions
const mutations = {
  setRoute(state, routes) {
    state.routePermissions = [...constantRoutes, ...routes]
  }
}

// actions
const actions = {
  setRoutes(store, routes) {
    // console.log(this.$store.state.user)  //不能这样获取,需要通过上面调用函数的时候传参
    const res = asyncRouters.filter(item => routes.includes(item.name))
    // console.log(routes[1])
    // console.log('stro/mou/permin', res)
    store.commit('setRoute', res)
  }

}

// 导出设置的过滤用户权限的全局数据
export default {
  namespaced: true, // 设置作用域
  state,
  mutations,
  actions
}
